package com.wuhongyu.service.impl;

import static org.hamcrest.CoreMatchers.nullValue;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wuhongyu.entity.Brand;
import com.wuhongyu.entity.BrandExample;
import com.wuhongyu.mapper.BrandMapper;
import com.wuhongyu.service.BrandService;

@Service
public class BrandServiceImpl implements BrandService{

	@Autowired
	private BrandMapper brandMapper;
	
	@Override
	public List<Brand> selectAll() {
		BrandExample brandExample = new BrandExample();
		brandExample.createCriteria();
		List<Brand> brandList = brandMapper.selectByExample(brandExample);
		return brandList;
	}

	@Override
	public Brand queryById(Integer id) {
		Brand brand = brandMapper.selectByPrimaryKey(id);
		return brand;
	}

	@Override
	public void updateOrInsert(Brand brand) {
		if(brand.getId()!=null && !"".equals(brand.getId())) {
			brandMapper.updateByPrimaryKeySelective(brand);
		}else {
			brandMapper.insertSelective(brand);
		}
	}

	@Override
	public void deleteById(Integer id) {
		brandMapper.deleteByPrimaryKey(id);
	}

	@Override
	public void deleteBath(Integer[] ids) {
		if(ids!=null) {
			List<Integer> idList = Arrays.asList(ids);
			brandMapper.deleteBath(idList);
		}
	}

}
